package durose.system.springUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import durose.system.pojo.Boss;

import com.github.pagehelper.Page;

import durose.system.service.DeptService;


/**
 * 获取分页对象，重新封装
 * @author Administrator
 *
 */
@Component
public class SpringBossFactory {

	@Autowired 
DeptService deptService; 

	
	
	public static SpringBossFactory me(){
		 return SpringContextHolder.getBean("springBossFactory");
	}
	//将List<Boss>格式的数据 改造成List<Map<String,Object>>类型，并在此处初始化一对多
	@SuppressWarnings("all")
	public List<Map<String,Object>> initData(Page page){
		Page pageNew = page;
		List<Boss> lists = pageNew.getResult();
		List<Map<String,Object>> mapList = new ArrayList<>();
		for(Boss boss:lists){
			Map<String,Object> map  = new HashMap<String, Object>();
			map.put("boss_id",boss.getBoss_id());
map.put("boss_name",boss.getBoss_name());
map.put("boss_number",boss.getBoss_number());
map.put("boss_dept",deptService.deptGet(boss.getBoss_dept()).getDept_name());
map.put("boss_sex",boss.getBoss_sex());
map.put("boss_date",boss.getBoss_date());

			mapList.add(map);
		}
		pageNew.clear();
		pageNew.addAll(mapList);
		return pageNew;
	}
	
	
}
